package com.han.bom.tests;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.han.bom.Exam;
import com.han.bom.PracticeExam;
import com.han.bom.Professor;
import com.han.bom.RealExam;
import com.han.bom.Student;

public class ProfessorTest {
	
	private Professor professor = null;
	private ArrayList <Student> students = new ArrayList<Student>();
	private ArrayList<Exam> exams = new ArrayList<Exam>();

	@Before
	public void setUp() throws Exception {
		this.professor = new Professor(1001);
		
		Student s1 = new Student(1002);
		Student s2 = new Student(1003);
		Student s3 = new Student(1004);
		Student s4 = new Student(1005);
		Student s5 = new Student(1006);
		this.students.add(s1);
		this.students.add(s2);
		this.students.add(s3);
		this.students.add(s4);
		this.students.add(s5);
		professor.setStudents(students);
		
		Exam e1 = new RealExam("First Exam", null);
		Exam e2 = new RealExam("Second Exam", null);
		Exam e3 = new RealExam("Third Exam", null);
		Exam e4 = new PracticeExam("Fourth Exam", null);
		Exam e5 = new PracticeExam("Fifth Exam", null);
		this.exams.add(e1);
		this.exams.add(e2);
		this.exams.add(e3);
		this.exams.add(e4);
		this.exams.add(e5);
		professor.setExams(exams);
	}

	@After
	public void tearDown() throws Exception {
		this.exams = null;
		this.students = null;
		this.professor = null;
	}
	@Test
	public void testSearchStudentString() {

		for(int x = 0; x<this.students.size(); x++){	
			assertEquals(this.students.get(x),professor.searchStudent(this.students.get(x).getUserID()));
		}
		
	}
	
	@Test
	public void testSearchStudentStudent() {
		for(int x =0; x<this.students.size(); x++){
			assertEquals(this.students.get(x),professor.searchStudent(this.students.get(x)));
		}
	}

	@Test
	public void testSearchExamString() {
		for(int x = 0; x<this.exams.size(); x++){			
			assertEquals(this.exams.get(x),professor.searchExam(this.exams.get(x).getExamID()));
		}
	}

	@Test
	public void testSearchExamExam() {
		for(int x = 0; x<this.exams.size(); x++){			
			assertEquals(this.exams.get(x),professor.searchExam(this.exams.get(x)));
		}
	}

	@Test
	public void testActivateExam() {
		for(int x = 0; x<this.exams.size(); x++){			
			if(this.exams.get(x) instanceof RealExam){				
				professor.activateExam((RealExam)professor.searchExam(this.exams.get(x)));
				assertEquals(true,((RealExam)(professor.searchExam(this.exams.get(x)))).isActivated());
			}
		}
		
	}

	@Test
	public void testDeactivateExam() {
		for(int x = 0; x<this.exams.size(); x++){
			if(this.exams.get(x) instanceof RealExam){
				professor.deactivateExam((RealExam)professor.searchExam(this.exams.get(x)));
				assertEquals(false,((RealExam)(professor.searchExam(this.exams.get(x)))).isActivated());
			}
		}
	}

}
